<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增人员信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <style type="text/css">
        button[type=submit]{
            display: none;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-info-add">
        <input name="openid" id="openid" type="hidden"  th:value="${openid}">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">姓名：</label>
            <div class="col-sm-4">
                <input id="userName" name="userName" class="form-control" placeholder="请输入姓名" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required" >身份证号码：</label>
            <div class="col-sm-4">
                <input id="identityCardNum" name="identityCardNum" class="form-control" placeholder="请输入身份证号码" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">用户性别：</label>
            <div class="col-sm-4">
                <select name="sex" id="sex"  class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">民族：</label>
            <div class="col-sm-4">
                <input id="nation" name="nation" class="form-control" placeholder="请输入民族" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">出生时间：</label>
            <div class="col-sm-4">
                <div class="input-group date">
                    <input id="birthTime" name="birthTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">年龄：</label>
            <div class="col-sm-4">
                <input id="age" name="age" class="form-control" placeholder="请输入年龄" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">电话：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input id="telephone" name="telephone" placeholder="请输入电话" class="form-control" type="text" maxlength="11" required>
                    <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">工作时间：</label>
            <div class="col-sm-4">
                <div class="input-group date">
                    <input id="wokeTime" name="wokeTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">第一学历：</label>
            <div class="col-sm-4">
                <select name="firstDegree"  id="firstDegree" class="form-control m-b">
                    <option value="">请选择学历</option>
                    <option value="高中以下">高中以下</option>
                    <option value="高中">高中</option>
                    <option value="大专">大专</option>
                    <option value="本科">本科</option>
                    <option value="硕士">硕士</option>
                    <option value="硕士">其他</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">第一学历毕业院校：</label>
            <div class="col-sm-4">
                <input id="graduateSchool" name="graduateSchool" class="form-control" placeholder="第一学历毕业院校" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">第一学历毕业专业：</label>
            <div class="col-sm-4">
                <input id="graduationMajor" name="graduationMajor" class="form-control" placeholder="第一学历毕业专业" type="text" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">最高学历：</label>
            <div class="col-sm-4">
                <select name="highestDegree"  id="highestDegree" class="form-control m-b">
                    <option value="">请选择学历</option>
                    <option value="高中以下">高中以下</option>
                    <option value="高中">高中</option>
                    <option value="大专">大专</option>
                    <option value="本科">本科</option>
                    <option value="硕士">硕士</option>
                    <option value="硕士">其他</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">最高学历毕业院校：</label>
            <div class="col-sm-4">
                <input id="school" name="school" class="form-control" placeholder="最高学历毕业院校" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">最高学历毕业专业：</label>
            <div class="col-sm-4">
                <input id="major" name="major" class="form-control" placeholder="最高学历毕业专业" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">家庭住址：</label>
            <div class="col-sm-4">
                <input id="address" name="address" class="form-control" placeholder="请输入家庭住址" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否党员：</label>
            <div class="col-sm-4">
                <!-- <input id="isParty" name="isParty" class="form-control" placeholder="请输入是否党员" type="text">-->
                <select id="isParty" name="isParty" class="form-control m-b" th:with="type=${@dict.getType('isParty')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">婚否：</label>
            <div class="col-sm-4">
                <!--<input id="isMarriage" name="isMarriage" class="form-control" placeholder="请输入婚否" type="text">-->
                <select id="isMarriage" name="isMarriage" class="form-control m-b" th:with="type=${@dict.getType('isMarriage')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">紧急联系人姓名：</label>
            <div class="col-sm-4">
                <input id="emergencyName" name="emergencyName" class="form-control" placeholder="请输入紧急联系人姓名" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">紧急联系电话：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input id="emergencyTelephone" name="emergencyTelephone" placeholder="请输入电话" class="form-control" type="text" maxlength="11">
                    <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">原工作单位名称：</label>
            <div class="col-sm-4">
                <input id="beforeCorporate" name="beforeCorporate" class="form-control" placeholder="请输入原工作单位名称" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">原工作岗位：</label>
            <div class="col-sm-4">
                <input id="beforePost" name="beforePost" class="form-control" placeholder="请输入原工作岗位" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-4">
                <textarea id="remark" name="remark" placeholder="请输入备注" class="form-control"></textarea>
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">微信openid：</label>
            <div class="col-sm-4">
                <input name="openid" class="form-control" type="text">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证照片：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f1">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f1" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学历证明：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f2">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f2" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学位证明：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f8">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f8" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">个人证件照：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f3">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f3" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工资银行卡号：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f4">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f4" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">职业资格证书：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f5">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f5" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">体检报告：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f6">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f6" name="file" type="file" multiple>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">户口本：</label>
            <div class="col-sm-4">
                <input type="hidden" name="f7">
                <div class="file-loading">
                    <input class="form-control file-upload" id="f7" name="file" type="file" multiple>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row" align="center">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-lg btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <br/>
        <br/>
        <!--<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>-->
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>

<script th:inline="javascript">
    var prefix = ctx + "system/info"

    $("#form-info-add").validate({
        onkeyup: false,
        rules:{
            telephone:{
                isPhone:true,
            },
            emergencyTelephone:{
                isPhone:true,
            },
            identityCardNum:{
                isIdentity:true,
            },
        },
        focusCleanup: true
    });


    function submitHandler() {
        if ($.validate.form()) {
            /*$.operate.save(prefix + "/add", $('#form-info-add').serialize());*/
            uploadFile();
        }
    }

    function uploadFile() {
        var formData = new FormData();
        formData.append('userName', $("#userName").val());
        formData.append('sex', $("#sex").val());
        formData.append('nation', $("#nation").val());
        formData.append('birthTime', $("#birthTime").val());

        if($("#age").val() != undefined) {
            formData.append('age', $("#age").val());
        }
        formData.append('wokeTime', $("#wokeTime").val());
        formData.append('firstDegree', $("#firstDegree").val());
        formData.append('highestDegree', $("#highestDegree").val());
        formData.append('identityCardNum', $("#identityCardNum").val());
        formData.append('graduateSchool', $("#graduateSchool").val());
        formData.append('graduationMajor', $("#graduationMajor").val());
        formData.append('school', $("#school").val());
        formData.append('openid',$("#openid").val())
        formData.append('major', $("#major").val());
        formData.append('telephone', $("#telephone").val());
        formData.append('address', $("#address").val());
        formData.append('isParty', $("#isParty").val());
        formData.append('isMarriage', $("#isMarriage").val());
        formData.append('emergencyName', $("#emergencyName").val());
        formData.append('emergencyTelephone', $("#emergencyTelephone").val());
        formData.append('beforeCorporate', $("#beforeCorporate").val());
        formData.append('beforePost', $("#beforePost").val());
        formData.append('remark', $("#remark").val());

        if ($('#f1')[0].files.length > 0) {
            for (var i = 0; i < $('#f1')[0].files.length; i++) {
                formData.append('files', $('#f1')[0].files[i],"sfz_"+i);
            }
        }

        if ($('#f2')[0].files.length > 0) {
            for (var i = 0; i < $('#f2')[0].files.length; i++) {
                formData.append('files', $('#f2')[0].files[i],"xlzm_"+i);
            }
        }
        if ($('#f3')[0].files.length > 0) {
            for (var i = 0; i < $('#f3')[0].files.length; i++) {
                formData.append('files', $('#f3')[0].files[i],"grzj_"+i);
            }
        }
        if ($('#f4')[0].files.length > 0) {
            for (var i = 0; i < $('#f4')[0].files.length; i++) {
                formData.append('files', $('#f4')[0].files[i],"gzyhkh_"+i);
            }
        }
        if ($('#f5')[0].files.length > 0) {
            for (var i = 0; i < $('#f5')[0].files.length; i++) {
                formData.append('files', $('#f5')[0].files[i],"zyzgzs_"+i);
            }
        }
        if ($('#f6')[0].files.length > 0) {
            for (var i = 0; i < $('#f6')[0].files.length; i++) {
                formData.append('files', $('#f6')[0].files[i],"tjbg_"+i);
            }
        }
        if ($('#f7')[0].files.length > 0) {
            for (var i = 0; i < $('#f7')[0].files.length; i++) {
                formData.append('files', $('#f7')[0].files[i],"hkb_"+i);
            }
        }
        if ($('#f8')[0].files.length > 0) {
            for (var i = 0; i < $('#f8')[0].files.length; i++) {
                formData.append('files', $('#f8')[0].files[i],"qtfj_"+i);
            }
        }
        $.ajax({
            url: prefix + "/add",
            type: 'post',
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            dataType: "json",
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    // $.operate.successCallback(result);
                    $.modal.alertSuccess(result.msg)
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            }
        });
    }


    $("#f1").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        layoutTemplates: {
            actionDelete: '',//预览页面的删除按钮设置为不显示
            actionUpload:''
        }
    });
    $("#f2").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f3").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f4").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f5").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f6").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f7").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });
    $("#f8").fileinput({
        maxFileCount: 5,
        dropZoneEnabled: false,
        showCaption: true,
        allowedFileExtensions: ['jpg', 'png', 'jpeg', "gif", "pdf"],
        initialPreviewAsData: true,
        overwriteInitial: true,
        /*layoutTemplates: {
            actionDelete: ''//预览页面的删除按钮设置为不显示
        }*/
    });

    $("input[name='birthTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='wokeTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>